package com.example.administrator.demo_dialog_box;

import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    AlertDialog.Builder builder;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        builder=new AlertDialog.Builder(MainActivity.this);
    }
    public void confirm_dialog(View view){
        AlertDialog.Builder builder=new AlertDialog.Builder(MainActivity.this);
        builder.setTitle("警告");
        builder.setMessage("对话框是否弹出?");
        builder.setNegativeButton("否",null);
        builder.setPositiveButton("是", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                Toast.makeText(MainActivity.this,"GG",0).show();
            }
        });
        builder.show();
    }
    public void radio_dialog(View view){

        builder.setTitle("请选择你的性别");
        final String[] items={"男","女","人妖"};
        builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                Toast.makeText(MainActivity.this,"你选择的性别是:"+items[i],0).show();
            }
        });
        builder.setNegativeButton("取消选择",null);
        builder.show();
    }
    public void multi_dialog(View view){
        builder.setTitle("请选择你喜欢的老师");
        final String[] items={"苍井空","波多野结衣","吉泽明步"};
        final boolean[] checkeditems={false,false,false};
        builder.setMultiChoiceItems(items, checkeditems, new DialogInterface.OnMultiChoiceClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i, boolean b) {
                Toast.makeText(MainActivity.this,"你选择的水果是:"+items[i]+b,0).show();
            }
        });
        builder.setNegativeButton("取消选择",null);
        builder.show();
    }
    public void progress_dialog(View view){
        final ProgressDialog pd=new ProgressDialog(this);
        pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        pd.setMax(100);
        new Thread(){
            public void run(){
                for (int i=0;i<=100;i++){
                    try {
                        Thread.sleep(300);
                        pd.setProgress(i);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                pd.dismiss();
            }
        }.start();
        pd.setMessage("正在加载你的老师");
        pd.show();
    }
    public void circle_dialog(View view){
        ProgressDialog pd=new ProgressDialog(this);
        pd.setMessage("正在加载你的老师");
        pd.show();
    }
}
